package edu.kjxy.worker0322;

import java.util.Scanner;

public class worker11 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		boolean[] isdie = new boolean[n];
		in.close();
		
		for (int i = 0; i < isdie.length; i++) {
			isdie[i] = true;                //初始全存活
		}
		int m = 0; //报数计数器
		int i = 0; //当前猴子索引
		while(n > 1) {
			m++;
			if(m == 3) {
				isdie[i] = false;
				m = 0;
				n--;
			}
			i = (i + 1) % n; //一种循环队列的解法
		}
		for (int j = 0; j < isdie.length; j++) {
			if(isdie[j] == true) {
				System.out.println(j + 1);   //找到唯一存活的那只猴子
				return;
			}
		}
	}
}
